package cn.south.campus.admin.sys.controller;

import cn.south.campus.admin.sys.model.req.SysMenuReq;
import cn.south.campus.admin.sys.model.vo.SysMenuVo;
import cn.south.campus.admin.sys.service.SysMenuService;
import cn.south.campus.common.model.bo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/10/31 13:24
 */
@RestController
@RequestMapping("admin/menu")
@AllArgsConstructor
public class SysMenuController {

    private final SysMenuService sysMenuService;

    @PostMapping("/add")
    public Result<String> add(@RequestBody SysMenuVo vo) {
        sysMenuService.add(vo);
        return Result.success("添加成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@PathVariable Long id) {
        sysMenuService.delete(id);
        return Result.success("删除成功");
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody SysMenuVo vo) {
        sysMenuService.updateMenu(vo);
        return Result.success("更新成功");
    }

    @GetMapping("/detail/{id}")
    public Result<SysMenuVo> detail(@PathVariable Long id) {
        return Result.success(sysMenuService.detail(id));
    }

    @GetMapping("/page")
    public Result<IPage<SysMenuVo>> page(SysMenuReq req) {
        return Result.success(sysMenuService.page(req));
    }

    @GetMapping("/list")
    public Result<List<SysMenuVo>> list(SysMenuReq req) {
        return Result.success(sysMenuService.list(req));
    }
}
